<?php
/*
Plugin Name: Zendvn Wordpress
Plugin URI: www.phung.com.vn
Description: Zendvn for Wordpress source.
Author: Minh Phung
Version: 1.0
Author URI: http://ma.tt/
*/

//Hook active
register_activation_hook(__FILE__, 'zendvn_wp_active');

/**
 * The function will active. When you click active link.
 */
function zendvn_wp_active() {
    
    // Create a table in database.
    global $wpdb;
    $table_name = $wpdb->prefix . 'zendvn_wp_test';

    if($wpdb->get_var('SHOW TABLES LIKE "'.$table_name.'"') != $table_name) {
        $sql = 'CREATE TABLE `'.$table_name.'` ('
            . '`myid` tinyint(4) unsigned NOT NULL AUTO_INCREMENT, '
            . '`myname` varchar(50) DEFAULT NULL, '
            . 'PRIMARY KEY (`myid`)'
            . ') ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;';
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        dbDelta($sql);
    }
    
    $zendvn_mp_version = "1.0";
	//Options API
	add_option("zendvn_wp_version",$zendvn_mp_version,'','yes');
}


// Hook deactive
register_deactivation_hook(__FILE__, 'zendvn_wp_deactive');

/**
 * The function will deactive. When you click deactive link
 */
function zendvn_wp_deactive() {
    global $wpdb;
    $table_name = $wpdb->prefix . 'options';
    
    $wpdb->update(
            $table_name,
            array('autoload' => 'no'),
            array('option_name' => 'zendvn_wp_version')
        );    
}


// Hook delete.
/*register_uninstall_hook(__FILE__, 'zendvn_wp_unistall');

/**
 * The function delete file and database.
 */
/*function zendvn_wp_unistall() {
    global $wpdb;
    
    delete_option('zendvn_wp_version');
    
    $table_name = $wpdb->prefix . 'zendvn_wp_test';
    $sql    = 'DROP TABLE IF EXISTS ' . $table_name;
    $wpdb->query($sql);
    
}*/